$(function(){
    createHistorySearch();

    $('#searchBtn').tap(searchFn);

    $("#main").on("tap","a",moreSearchFn);

    function HistoryObjToArr(obj){
        var arr = []
        for (var i in obj) {
            arr.push(obj[i]); //属性
        }
        return arr;
    }

    function createHistorySearch(){
        var searchHistory = LsyStorage.getItem("searchHistory");
        searchHistory =  HistoryObjToArr(searchHistory);
        console.log(searchHistory);
        var str = '';
        searchHistory.forEach(function (i) {
            str += '<li><a href="">'+i+'</a> </li>'
        });
        $("#history").html(str);
    }

    function moreSearchFn(){
        var search = $(this).text();
        window.location.href = "pro_list.html?search="+search;
    }

    function searchFn() {
        var search = $('#mainSearch').val();
        search = search.replace(/~\s+/, '').replace(/~\s+$/, '');
        if (!search) {
            window.location.href = "pro_list.html";
        }
        window.location.href = "pro_list.html?search="+search;
    }

});
